package com.zhou.JavaAndroidFirm.model;

import com.zhou.JavaAndroidFirm.bean.GirlData;
import com.zhou.JavaAndroidFirm.bean.PhotoGirl;
import com.zhou.JavaAndroidFirm.constract.PhotosListContract;
import com.zhou.JavaAndroidFirm.http.ApiConstants;
import com.zhou.JavaAndroidFirm.http.HttpService;
import com.zhou.JavaAndroidFirm.http.HttpUtils;
import com.zhou.JavaAndroidFirm.rx.RxSchedulers;

import java.util.List;

import rx.Observable;
import rx.functions.Func1;

/**
 * @author Administrator
 * @date 2018/7/18 0018
 * @des
 */
public class PhotosListModel implements PhotosListContract.Model {
    @Override
    public Observable<List<PhotoGirl>> getPhotosListData(int size, int page) {
        return HttpUtils.getInstance()
                .getRetofitClinet()
                .setBaseUrl(ApiConstants.SINA_PHOTO_HOST_BASEURL)
                .builder(HttpService.class)
                .getPhotoList(size, page)
                .map(new Func1<GirlData, List<PhotoGirl>>() {
                    @Override
                    public List<PhotoGirl> call(GirlData girlData) {
                        return girlData.getResults();
                    }
                })
                .compose(RxSchedulers.<List<PhotoGirl>>io_main());
    }
}
